/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MowerInterface.java
 *
 * Created on Jul 25, 2011, 1:28:46 AM
 */

package mowbot;

import mowbot.camera.CameraInterface;
import mowbot.serial.SerialInterface;
import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @author Justin
 */
public class MowerInterface extends javax.swing.JFrame  {

    CommonInterface commonInterface_;
    CameraInterface camera_;

    boolean needToStopCamera_ = false;
    double lastCameraDirection_ = 0.0;

    public final static  int FORWARD_BACKWARD_AXIS_ID = 1;
    public final static  int LEFT_RIGHT_AXIS_ID = 0;

    boolean PATROL_LEFT_RIGHT_BUTTON_STATE = false;
    boolean PATROL_UP_DOWN_BUTTON_STATE = false;

    boolean POWER_BUTTON_STATE = false;
    boolean HONK_BUTTON_STATE = false;
    boolean INC_SPEED_BUTTON_STATE = false;
    boolean DEC_SPEED_BUTTON_STATE = false;

    boolean STOP_BUTTON_STATE = false;

    long lastTurnSerial = 0;
    long lastGoSerial   = 0;

    public int SERIAL_REFRESH_RATE = 30;
    public int FR_MIN0 = 76;
    public int FR_MIN1 = 100;
    public int FR_MAX0 = 148;
    public int FR_MAX1 = 190;

    public int LR_MIN0 = 81;
    public int LR_MIN1 = 108;
    public int LR_MAX0 = 150;
    public int LR_MAX1 = 169;


    java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
    /** Creates new form MowerInterface */
    public MowerInterface(CommonInterface s, CameraInterface c) {
        initComponents();

        commonInterface_ = s;
        camera_ = c;

        initConfigValues();

        updateConfigValues();

        this.addKeyListener(new KeyListener()
        {
            public void keyPressed(KeyEvent e) {mainKeyPressed(e); }

            public void keyReleased(KeyEvent e) { mainKeyReleased(e); }

            public void keyTyped(KeyEvent e) { mainKeyTyped(e); }
        });
   
    }
public void initConfigValues()
    {
        this.refreshRateSlider.setValue(SERIAL_REFRESH_RATE);


        this.frMin0Slider.setValue(FR_MIN0);
        this.frMin1Slider.setValue(FR_MIN1);
        this.frMax0Slider.setValue(FR_MAX0);
        this.frMax1Slider.setValue(FR_MAX1);

        this.lrMinSlider0.setValue(LR_MIN0);
        this.lrMin1Slider.setValue(LR_MIN1);
        this.lrMax0Slider.setValue(LR_MAX0);
       this.lrMax1Slider.setValue(LR_MAX1);
    }
    public void updateConfigValues()
    {

        return;
        /*
        SERIAL_REFRESH_RATE = this.refreshRateSlider.getValue();

        this.refreshRateLabel.setText(String.valueOf(SERIAL_REFRESH_RATE));
        
        FR_MIN0 = this.frMin0Slider.getValue();
        FR_MIN1 = this.frMin1Slider.getValue();
        FR_MAX0 = this.frMax0Slider.getValue();
        FR_MAX1 = this.frMax1Slider.getValue();

        LR_MIN0 = this.lrMinSlider0.getValue();
        LR_MIN1 = this.lrMin1Slider.getValue();
        LR_MAX0 = this.lrMax0Slider.getValue();
        LR_MAX1 = this.lrMax1Slider.getValue();

        this.frMin0Label.setText(String.valueOf(FR_MIN0));
        this.frMin1Label.setText(String.valueOf(FR_MIN1));
        this.frMax0Label.setText(String.valueOf(FR_MAX0));
        this.frMax1Label.setText(String.valueOf(FR_MAX1));
        this.lrMin0Label.setText(String.valueOf(LR_MIN0));
        this.lrMin1Label.setText(String.valueOf(LR_MIN1));
        this.lrMax0Label.setText(String.valueOf(LR_MAX0));
        this.lrMax1Label.setText(String.valueOf(LR_MAX1));
         * 
         */
    }

    /** Handle the key typed event from the text field. */
    public void mainKeyTyped(KeyEvent e) {
        System.out.println(e.getKeyText(e.getKeyCode()) + "KEY TYPED: ");
    }

    /** Handle the key pressed event from the text field. */
    public void mainKeyPressed(KeyEvent e) {
        System.out.println(e.getKeyText(e.getKeyCode()) + "KEY PRESSED: ");
    }

    /** Handle the key released event from the text field. */
    public void mainKeyReleased(KeyEvent e) {
        System.out.println(e.getKeyText(e.getKeyCode()) + "KEY RELEASED: ");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        togglePowerButton = new javax.swing.JButton();
        honkButton = new javax.swing.JButton();
        maxSpeedUpButton = new javax.swing.JButton();
        MaxSpeedDownButton = new javax.swing.JButton();
        forwardButton = new javax.swing.JButton();
        turnLeftButton = new javax.swing.JButton();
        turnRightButton = new javax.swing.JButton();
        reverseButton = new javax.swing.JButton();
        stopButton = new javax.swing.JButton();
        cameraLeftButton = new javax.swing.JButton();
        cameraUpButton = new javax.swing.JButton();
        cameraDownButton = new javax.swing.JButton();
        cameraRightButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        stopCameraButton = new javax.swing.JButton();
        centerCameraButton = new javax.swing.JButton();
        upDownSlider = new javax.swing.JSlider();
        leftRightSlider = new javax.swing.JSlider();
        powerRadio = new javax.swing.JRadioButton();
        speedUpRadio = new javax.swing.JRadioButton();
        honkRadio = new javax.swing.JRadioButton();
        speedDownRadio = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        hatValueLabel = new javax.swing.JLabel();
        joystickStateLabel = new javax.swing.JLabel();
        invertAxisCheckbox = new javax.swing.JCheckBox();
        frMin0Slider = new javax.swing.JSlider();
        frMin1Slider = new javax.swing.JSlider();
        frMax0Slider = new javax.swing.JSlider();
        frMax1Slider = new javax.swing.JSlider();
        lrMinSlider0 = new javax.swing.JSlider();
        lrMin1Slider = new javax.swing.JSlider();
        lrMax0Slider = new javax.swing.JSlider();
        lrMax1Slider = new javax.swing.JSlider();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        refreshRateSlider = new javax.swing.JSlider();
        jLabel16 = new javax.swing.JLabel();
        frMin0Label = new javax.swing.JLabel();
        frMin1Label = new javax.swing.JLabel();
        frMax0Label = new javax.swing.JLabel();
        frMax1Label = new javax.swing.JLabel();
        lrMin0Label = new javax.swing.JLabel();
        lrMin1Label = new javax.swing.JLabel();
        lrMax0Label = new javax.swing.JLabel();
        lrMax1Label = new javax.swing.JLabel();
        refreshRateLabel = new javax.swing.JLabel();
        frValueLabel = new javax.swing.JLabel();
        lrValueLabel = new javax.swing.JLabel();
        forceInitButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        togglePowerButton.setText("Toggle Power");
        togglePowerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                togglePowerButtonActionPerformed(evt);
            }
        });

        honkButton.setText("Honk!");
        honkButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                honkButtonActionPerformed(evt);
            }
        });

        maxSpeedUpButton.setText("Max Speed++");
        maxSpeedUpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                maxSpeedUpButtonActionPerformed(evt);
            }
        });

        MaxSpeedDownButton.setText("Max Speed--");
        MaxSpeedDownButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MaxSpeedDownButtonActionPerformed(evt);
            }
        });

        forwardButton.setText("^");
        forwardButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                forwardButtonActionPerformed(evt);
            }
        });

        turnLeftButton.setText("<");
        turnLeftButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                turnLeftButtonActionPerformed(evt);
            }
        });

        turnRightButton.setText(">");
        turnRightButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                turnRightButtonActionPerformed(evt);
            }
        });

        reverseButton.setText("V");
        reverseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reverseButtonActionPerformed(evt);
            }
        });

        stopButton.setText("STOP!");
        stopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopButtonActionPerformed(evt);
            }
        });

        cameraLeftButton.setText("<");
        cameraLeftButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cameraLeftButtonActionPerformed(evt);
            }
        });

        cameraUpButton.setText("^");
        cameraUpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cameraUpButtonActionPerformed(evt);
            }
        });

        cameraDownButton.setText("V");
        cameraDownButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cameraDownButtonActionPerformed(evt);
            }
        });

        cameraRightButton.setText(">");
        cameraRightButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cameraRightButtonActionPerformed(evt);
            }
        });

        jLabel1.setText("Bot Control");

        jLabel2.setText("Camera Control");

        stopCameraButton.setText("STOP!");
        stopCameraButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopCameraButtonActionPerformed(evt);
            }
        });

        centerCameraButton.setText("O");
        centerCameraButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                centerCameraButtonActionPerformed(evt);
            }
        });

        upDownSlider.setMaximum(255);
        upDownSlider.setValue(127);
        upDownSlider.setEnabled(false);
        upDownSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                upDownSliderStateChanged(evt);
            }
        });

        leftRightSlider.setMaximum(255);
        leftRightSlider.setValue(127);
        leftRightSlider.setEnabled(false);

        powerRadio.setText("Power Button");
        powerRadio.setEnabled(false);
        powerRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                powerRadioActionPerformed(evt);
            }
        });

        speedUpRadio.setText("Max Speed++");
        speedUpRadio.setEnabled(false);

        honkRadio.setText("Honk Button");
        honkRadio.setEnabled(false);

        speedDownRadio.setText("Max Speed--");
        speedDownRadio.setEnabled(false);

        jLabel3.setText("Pan Directional (Hat):");

        jLabel4.setText("Reverse");

        jLabel5.setText("Forward");

        jLabel6.setText("Left");

        jLabel7.setText("Right");

        hatValueLabel.setText("                   ");

        joystickStateLabel.setText("                       ");

        invertAxisCheckbox.setText("Invert Forward/Backward");
        invertAxisCheckbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                invertAxisCheckboxActionPerformed(evt);
            }
        });

        frMin0Slider.setMaximum(127);
        frMin0Slider.setValue(0);
        frMin0Slider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                frMin0SliderStateChanged(evt);
            }
        });

        frMin1Slider.setMaximum(127);
        frMin1Slider.setValue(127);
        frMin1Slider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                frMin1SliderStateChanged(evt);
            }
        });

        frMax0Slider.setMaximum(255);
        frMax0Slider.setMinimum(127);
        frMax0Slider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                frMax0SliderStateChanged(evt);
            }
        });

        frMax1Slider.setMaximum(255);
        frMax1Slider.setMinimum(127);
        frMax1Slider.setValue(255);
        frMax1Slider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                frMax1SliderStateChanged(evt);
            }
        });

        lrMinSlider0.setMaximum(127);
        lrMinSlider0.setValue(0);
        lrMinSlider0.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                lrMinSlider0StateChanged(evt);
            }
        });

        lrMin1Slider.setMaximum(127);
        lrMin1Slider.setValue(127);
        lrMin1Slider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                lrMin1SliderStateChanged(evt);
            }
        });

        lrMax0Slider.setMaximum(255);
        lrMax0Slider.setMinimum(127);
        lrMax0Slider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                lrMax0SliderStateChanged(evt);
            }
        });

        lrMax1Slider.setMaximum(255);
        lrMax1Slider.setMinimum(127);
        lrMax1Slider.setValue(255);
        lrMax1Slider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                lrMax1SliderStateChanged(evt);
            }
        });

        jLabel8.setText("F/R Min0");

        jLabel9.setText("F/R Min1");

        jLabel10.setText("F/R Max0");

        jLabel11.setText("F/R Max1");

        jLabel12.setText("L/R Min0");

        jLabel13.setText("L/R Min1");

        jLabel14.setText("L/R Max0");

        jLabel15.setText("L/R Max1");

        refreshRateSlider.setMaximum(500);
        refreshRateSlider.setValue(250);
        refreshRateSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                refreshRateSliderStateChanged(evt);
            }
        });

        jLabel16.setText("RefreshRate");

        frMin0Label.setText("jLabel17");

        frMin1Label.setText("jLabel18");

        frMax0Label.setText("jLabel19");

        frMax1Label.setText("jLabel20");

        lrMin0Label.setText("jLabel21");

        lrMin1Label.setText("jLabel22");

        lrMax0Label.setText("jLabel23");

        lrMax1Label.setText("jLabel24");

        refreshRateLabel.setText("jLabel25");

        frValueLabel.setText("jLabel17");

        lrValueLabel.setText("jLabel18");

        forceInitButton.setText("Force Init");
        forceInitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                forceInitButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(58, 58, 58)
                                .addComponent(lrValueLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel7))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(37, 37, 37)
                                .addComponent(frValueLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel5))
                            .addComponent(upDownSlider, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(invertAxisCheckbox)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(powerRadio)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(honkRadio)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel13)
                                    .addComponent(jLabel14)))
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lrMin1Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lrMax1Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lrMax0Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(leftRightSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(speedUpRadio)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(speedDownRadio))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(hatValueLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE))
                            .addComponent(joystickStateLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(MaxSpeedDownButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(maxSpeedUpButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(honkButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(togglePowerButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(forceInitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(turnLeftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(32, 32, 32)
                                                .addComponent(turnRightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(45, 45, 45)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(forwardButton)
                                                    .addComponent(reverseButton)))
                                            .addComponent(stopButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addGap(54, 54, 54)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(stopCameraButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(cameraLeftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                    .addComponent(cameraUpButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .addComponent(cameraDownButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .addComponent(centerCameraButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addGap(31, 31, 31)
                                                .addComponent(jLabel2)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cameraRightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(71, 71, 71)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel12))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(frMin1Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(frMax0Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(frMax1Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(frMin0Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(lrMinSlider0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(4, 4, 4))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(refreshRateSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(frMin0Label)
                                        .addComponent(frMin1Label))
                                    .addComponent(frMax0Label))
                                .addComponent(frMax1Label)
                                .addComponent(lrMin0Label))
                            .addComponent(lrMin1Label)
                            .addComponent(lrMax0Label))
                        .addComponent(lrMax1Label))
                    .addComponent(refreshRateLabel))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(togglePowerButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(honkButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(maxSpeedUpButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(MaxSpeedDownButton))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(forwardButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(turnLeftButton)
                                    .addComponent(turnRightButton))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(reverseButton)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(stopButton)
                            .addComponent(forceInitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel8)
                                .addComponent(frMin0Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(frMin0Label)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(cameraUpButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(centerCameraButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cameraDownButton))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(frMin1Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(6, 6, 6)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(frMax0Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(cameraLeftButton)
                                                        .addComponent(cameraRightButton))
                                                    .addComponent(frMax0Label)))
                                            .addComponent(frMin1Label))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(frMax1Label)
                                            .addComponent(frMax1Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lrMin0Label)
                                    .addComponent(stopCameraButton)
                                    .addComponent(lrMinSlider0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel11)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel12)))
                        .addGap(6, 6, 6)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(invertAxisCheckbox)
                                .addComponent(frValueLabel)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(upDownSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(powerRadio)
                                .addComponent(honkRadio)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(lrValueLabel)))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel14)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel15))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lrMin1Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lrMin1Label))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lrMax0Label)
                                    .addComponent(lrMax0Slider, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lrMax1Slider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(lrMax1Label))))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(leftRightSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(speedUpRadio)
                                .addComponent(speedDownRadio)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(hatValueLabel))
                        .addGap(18, 18, 18)
                        .addComponent(joystickStateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(refreshRateLabel)
                            .addComponent(refreshRateSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16)))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void togglePowerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_togglePowerButtonActionPerformed
        // TODO add your handling code here:
        System.out.println("Action Performed...?");
        commonInterface_.writeData("1E");
    }//GEN-LAST:event_togglePowerButtonActionPerformed

    private void honkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_honkButtonActionPerformed
        // TODO add your handling code here:
        commonInterface_.writeData("3E");
    }//GEN-LAST:event_honkButtonActionPerformed

    private void maxSpeedUpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maxSpeedUpButtonActionPerformed
        // TODO add your handling code here:
        commonInterface_.writeData("5E");
    }//GEN-LAST:event_maxSpeedUpButtonActionPerformed

    private void MaxSpeedDownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MaxSpeedDownButtonActionPerformed
        // TODO add your handling code here:
        commonInterface_.writeData("4E");
    }//GEN-LAST:event_MaxSpeedDownButtonActionPerformed

    private void turnLeftButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_turnLeftButtonActionPerformed
        // TODO add your handling code here:
        commonInterface_.writeData("T80E");
    }//GEN-LAST:event_turnLeftButtonActionPerformed

    private void forwardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_forwardButtonActionPerformed
        // TODO add your handling code here:
        commonInterface_.writeData("F220E");
    }//GEN-LAST:event_forwardButtonActionPerformed

    private void turnRightButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_turnRightButtonActionPerformed
        // TODO add your handling code here:
        commonInterface_.writeData("T200E");
    }//GEN-LAST:event_turnRightButtonActionPerformed

    private void reverseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reverseButtonActionPerformed
        // TODO add your handling code here:
        commonInterface_.writeData("F80E");
    }//GEN-LAST:event_reverseButtonActionPerformed

    private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed
        // TODO add your handling code here:
        commonInterface_.writeData("F127.5ET127.5E");
    }//GEN-LAST:event_stopButtonActionPerformed

    private void cameraLeftButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cameraLeftButtonActionPerformed
        // TODO add your handling code here:
        camera_.runCommand(CameraInterface.PAN_LEFT);
    }//GEN-LAST:event_cameraLeftButtonActionPerformed

    private void cameraUpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cameraUpButtonActionPerformed
        // TODO add your handling code here:
        camera_.runCommand(CameraInterface.PAN_UP);
    }//GEN-LAST:event_cameraUpButtonActionPerformed

    private void cameraDownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cameraDownButtonActionPerformed
        // TODO add your handling code here:
        camera_.runCommand(CameraInterface.PAN_DOWN);
    }//GEN-LAST:event_cameraDownButtonActionPerformed

    private void cameraRightButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cameraRightButtonActionPerformed
        // TODO add your handling code here:
        camera_.runCommand(CameraInterface.PAN_RIGHT);
    }//GEN-LAST:event_cameraRightButtonActionPerformed

    private void stopCameraButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopCameraButtonActionPerformed
        // TODO add your handling code here:
        camera_.StopCamera();
    }//GEN-LAST:event_stopCameraButtonActionPerformed

    private void centerCameraButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_centerCameraButtonActionPerformed
        // TODO add your handling code here:
        camera_.runCommand(CameraInterface.CENTER_CAMERA);
    }//GEN-LAST:event_centerCameraButtonActionPerformed

    private void powerRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_powerRadioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_powerRadioActionPerformed

    private void invertAxisCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_invertAxisCheckboxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_invertAxisCheckboxActionPerformed

    private void frMin0SliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_frMin0SliderStateChanged
        // TODO add your handling code here:
         updateConfigValues();
    }//GEN-LAST:event_frMin0SliderStateChanged

    private void frMin1SliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_frMin1SliderStateChanged
        // TODO add your handling code here:
         updateConfigValues();
    }//GEN-LAST:event_frMin1SliderStateChanged

    private void frMax0SliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_frMax0SliderStateChanged
        // TODO add your handling code here:
         updateConfigValues();
    }//GEN-LAST:event_frMax0SliderStateChanged

    private void frMax1SliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_frMax1SliderStateChanged
        // TODO add your handling code here:
        updateConfigValues();
    }//GEN-LAST:event_frMax1SliderStateChanged

    private void lrMinSlider0StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_lrMinSlider0StateChanged
        // TODO add your handling code here:
         updateConfigValues();
    }//GEN-LAST:event_lrMinSlider0StateChanged

    private void lrMin1SliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_lrMin1SliderStateChanged
        // TODO add your handling code here:
         updateConfigValues();
    }//GEN-LAST:event_lrMin1SliderStateChanged

    private void lrMax0SliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_lrMax0SliderStateChanged
        // TODO add your handling code here:
         updateConfigValues();

    }//GEN-LAST:event_lrMax0SliderStateChanged

    private void lrMax1SliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_lrMax1SliderStateChanged
        // TODO add your handling code here:
        updateConfigValues();
    }//GEN-LAST:event_lrMax1SliderStateChanged

    private void refreshRateSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_refreshRateSliderStateChanged
        // TODO add your handling code here:
         updateConfigValues();
    }//GEN-LAST:event_refreshRateSliderStateChanged

    private void upDownSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_upDownSliderStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_upDownSliderStateChanged

    private void forceInitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_forceInitButtonActionPerformed
        // TODO add your handling code here:

        commonInterface_.writeData("ZZZ");
    }//GEN-LAST:event_forceInitButtonActionPerformed
    public void SetHatValue(int r, double v){
        this.hatValueLabel.setText(String.valueOf(r)+","+String.valueOf(v));
        if(v >= 1)
        {

            if(r == mowbot.joystick.Joystick.HAT_UP  && (needToStopCamera_ == false || lastCameraDirection_ != mowbot.joystick.Joystick.HAT_UP ))
            {
                camera_.runCommand(CameraInterface.PAN_UP);
            }else if(r == mowbot.joystick.Joystick.HAT_LEFT && (needToStopCamera_ == false || lastCameraDirection_ != mowbot.joystick.Joystick.HAT_LEFT ))
            {
                camera_.runCommand(CameraInterface.PAN_LEFT);
            }else if(r == mowbot.joystick.Joystick.HAT_LEFT && (needToStopCamera_ == false || lastCameraDirection_ != mowbot.joystick.Joystick.HAT_LEFT ))
            {
                camera_.runCommand(CameraInterface.PAN_LEFT);
            }else if(r == mowbot.joystick.Joystick.HAT_RIGHT && (needToStopCamera_ == false || lastCameraDirection_ != mowbot.joystick.Joystick.HAT_RIGHT ))
            {
                camera_.runCommand(CameraInterface.PAN_RIGHT);
            }else if(r == mowbot.joystick.Joystick.HAT_DOWN && (needToStopCamera_ == false || lastCameraDirection_ != mowbot.joystick.Joystick.HAT_DOWN ))
            {
                camera_.runCommand(CameraInterface.PAN_DOWN);
            }

            needToStopCamera_ = true;
            lastCameraDirection_ = r;
        }else{
            if(needToStopCamera_)
            {
                 camera_.StopCamera();
                 needToStopCamera_ = false;
            }
        }

    }

    public void ButtonDown(int b)
    {
        switch(b)
        {
            case 0:
                if(!this.POWER_BUTTON_STATE){
                    commonInterface_.writeData("1E");
                    POWER_BUTTON_STATE = true;
                    this.powerRadio.setSelected(true);
                }
                break;
            case 1:
                if(!this.HONK_BUTTON_STATE){
                    commonInterface_.writeData("3E");
                    HONK_BUTTON_STATE = true;
                    this.honkRadio.setSelected(true);
                }
                break;
            case 2:
                if(!this.DEC_SPEED_BUTTON_STATE){
                    commonInterface_.writeData("4E");
                    DEC_SPEED_BUTTON_STATE = true;
                    this.speedDownRadio.setSelected(true);
                }
                break;
            case 3:
                if(!this.INC_SPEED_BUTTON_STATE){
                    commonInterface_.writeData("5E");
                    INC_SPEED_BUTTON_STATE = true;
                    this.speedUpRadio.setSelected(true);
                }
                break;
            case 4:
                if(!this.PATROL_LEFT_RIGHT_BUTTON_STATE){
                    camera_.runCommand(CameraInterface.HORIZON_PATROL);
                    PATROL_LEFT_RIGHT_BUTTON_STATE = true;
                }
                break;
            case 5:
                if(!this.PATROL_UP_DOWN_BUTTON_STATE){
                    camera_.runCommand(CameraInterface.VERTICAL_PATROL);
                    PATROL_UP_DOWN_BUTTON_STATE = true;
                }
                break;
            default:
                System.out.println("WARNING: UNMAPPED BUTTON ("+b+") in MowerInterface.");

        }
    }

    public void SetJoystickStateLabel(String s){
        this.joystickStateLabel.setText(s);
    }

    public void UpdateJoystickAxis(int id, double value){

        double tvalue = value*-1;

        double serialValue = 127.5;
        if(id == FORWARD_BACKWARD_AXIS_ID){
            if(this.invertAxisCheckbox.isSelected()){
                tvalue = value;
            }
            if((int)(tvalue*100) > 0){
                double v = FR_MAX0+(FR_MAX1 - FR_MAX0)*tvalue;
                this.upDownSlider.setValue((int)v);
                serialValue =  FR_MAX0+(FR_MAX1 - FR_MAX0)*tvalue;

            }else if ((int)(tvalue*100) < 0){
                double v = FR_MIN1+((FR_MIN1-FR_MIN0)*tvalue);
                this.upDownSlider.setValue((int)v);
                serialValue = FR_MIN1+((FR_MIN1-FR_MIN0)*tvalue);
            }

            if(this.lastGoSerial == 0 || ((System.currentTimeMillis() - this.lastGoSerial) > SERIAL_REFRESH_RATE))
            {
                this.frValueLabel.setText(df.format(serialValue)+" ("+df.format(value)+")");
                commonInterface_.writeData("F"+df.format(serialValue)+"E");
                this.lastGoSerial = System.currentTimeMillis();
            }
        }else if(id == LEFT_RIGHT_AXIS_ID){
            if((int)(value*100) > 0){
                double v = LR_MAX0+(LR_MAX1 - LR_MAX0)*value;
                this.leftRightSlider.setValue((int)v);
                serialValue = LR_MAX0+(LR_MAX1 - LR_MAX0)*value;
            }else if ((int)(value*100) < 0){
                double v = LR_MIN1+((LR_MIN1-LR_MIN0)*value);
                this.leftRightSlider.setValue((int)v);
                serialValue = LR_MIN1+((LR_MIN1-LR_MIN0)*value);
            }
            
            if(this.lastTurnSerial == 0 || ((System.currentTimeMillis() - this.lastTurnSerial) > SERIAL_REFRESH_RATE))
            {
                this.lrValueLabel.setText(df.format(serialValue)+" ("+df.format(value)+")");
                commonInterface_.writeData("T"+ df.format(serialValue)+"E");
                this.lastTurnSerial = System.currentTimeMillis();
            }
        }
    }

    public void ButtonUp(int b){
        switch(b)
        {
            case 0: //TOGGLE POWER
                this.powerRadio.setSelected(false);
                this.POWER_BUTTON_STATE = false;
                break;
            case 1: //HONK
                this.honkRadio.setSelected(false);
                this.HONK_BUTTON_STATE = false;
                break;
            case 2: //SPEED DOWN
                this.speedDownRadio.setSelected(false);
                this.DEC_SPEED_BUTTON_STATE = false;
                break;
            case 3: //SPEED UP
                this.speedUpRadio.setSelected(false);
                this.INC_SPEED_BUTTON_STATE = false;
                break;
            case 4:
                    PATROL_LEFT_RIGHT_BUTTON_STATE = false;
                break;
            case 5:
                    PATROL_UP_DOWN_BUTTON_STATE = false;
                break;
            default:
               // System.out.println("WARNING: UNMAPPED BUTTON ("+b+") in MowerInterface.");

        }

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton MaxSpeedDownButton;
    private javax.swing.JButton cameraDownButton;
    private javax.swing.JButton cameraLeftButton;
    private javax.swing.JButton cameraRightButton;
    private javax.swing.JButton cameraUpButton;
    private javax.swing.JButton centerCameraButton;
    private javax.swing.JButton forceInitButton;
    private javax.swing.JButton forwardButton;
    private javax.swing.JLabel frMax0Label;
    private javax.swing.JSlider frMax0Slider;
    private javax.swing.JLabel frMax1Label;
    private javax.swing.JSlider frMax1Slider;
    private javax.swing.JLabel frMin0Label;
    private javax.swing.JSlider frMin0Slider;
    private javax.swing.JLabel frMin1Label;
    private javax.swing.JSlider frMin1Slider;
    private javax.swing.JLabel frValueLabel;
    private javax.swing.JLabel hatValueLabel;
    private javax.swing.JButton honkButton;
    private javax.swing.JRadioButton honkRadio;
    private javax.swing.JCheckBox invertAxisCheckbox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel joystickStateLabel;
    private javax.swing.JSlider leftRightSlider;
    private javax.swing.JLabel lrMax0Label;
    private javax.swing.JSlider lrMax0Slider;
    private javax.swing.JLabel lrMax1Label;
    private javax.swing.JSlider lrMax1Slider;
    private javax.swing.JLabel lrMin0Label;
    private javax.swing.JLabel lrMin1Label;
    private javax.swing.JSlider lrMin1Slider;
    private javax.swing.JSlider lrMinSlider0;
    private javax.swing.JLabel lrValueLabel;
    private javax.swing.JButton maxSpeedUpButton;
    private javax.swing.JRadioButton powerRadio;
    private javax.swing.JLabel refreshRateLabel;
    private javax.swing.JSlider refreshRateSlider;
    private javax.swing.JButton reverseButton;
    private javax.swing.JRadioButton speedDownRadio;
    private javax.swing.JRadioButton speedUpRadio;
    private javax.swing.JButton stopButton;
    private javax.swing.JButton stopCameraButton;
    private javax.swing.JButton togglePowerButton;
    private javax.swing.JButton turnLeftButton;
    private javax.swing.JButton turnRightButton;
    private javax.swing.JSlider upDownSlider;
    // End of variables declaration//GEN-END:variables

}
